package com.ruoyi.web.controller.util;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : Xuzhaobo
 * @date : 2025-02-14 14:41
 * @description :
 **/
@Component
public class ExportProgressUtil {
    private final Map<String, Integer> progressMap = new ConcurrentHashMap<>();
    private final Map<String, String> filePathMap = new ConcurrentHashMap<>();

    public void initTask(String taskId) {
        progressMap.put(taskId, 0);
    }

    public void updateProgress(String taskId, int progress) {
        progressMap.put(taskId, progress);
    }

    public int getProgress(String taskId) {
        return progressMap.getOrDefault(taskId, -1);
    }

    public void setFilePath(String taskId, String filePath) {
        filePathMap.put(taskId, filePath);
    }

    public String getFilePath(String taskId) {
        return filePathMap.get(taskId);
    }

    public void removeTask(String taskId) {
        progressMap.remove(taskId);
        filePathMap.remove(taskId);
    }
}
